﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EBA.Dynamic;
using System.Dynamic;
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;

namespace EBA.Tests.Dynamic
{
    /// <summary>
    /// Summary description for DuckTyping
    /// </summary>
    [TestClass]

    public class ObjectPropertyTest
    {
        [TestCategory("Dynamic")]
        [TestMethod]
        public void build_property_getter()
        {
            var obj = new DataObject();
            var data = obj.DynamicCastTo<IDataObject>();

            Assert.AreEqual("DataObject", data.Name);
        }


        [TestCategory("Dynamic")]
        [TestMethod]
        public void build_property_setter()
        {
            var obj = new DataObject();
            var data = obj.DynamicCastTo<IDataObject>();

            data.Name = "NewNameByDynamicSetter";

            Assert.AreEqual("NewNameByDynamicSetter", obj.Name);
        }

        [TestCategory("Dynamic")]
        [TestMethod]
        public void build_property_enum()
        {
            var obj = new DataObject();
            var data = obj.DynamicCastTo<IDataObject>();
            Assert.AreEqual("yes", data.judge.ToString());
        }

        [TestCategory("Dynamic")]
        [TestMethod]
        public void build_property_struct()
        {
            var obj = new DataObject();
            var data = obj.DynamicCastTo<IDataObject>();
            Assert.AreEqual(2, data.Num.ToString());
            Assert.AreEqual(DateTime.Parse("2013-02-26"), data.Time);
        }


        #region Helpers

        public enum Judge
        {
            yes,
            no
        }

        public interface IDataObject
        {
            string Name { get; set; }

            Judge judge { get; }

            int Num { get; set; }

            DateTime Time { get; set; }
        }

        public class DataObject : IDataObject
        {
            public DataObject()
            {
                this.Name = "DataObject";
                this.Num = 2;
                this.Time = DateTime.Parse("2013-02-26");
            }

            public string Name
            {
                get;
                set;
            }

            public int Num
            {
                get;
                set;
            }

            public DateTime Time
            {
                get;
                set;
            }


            public Judge judge
            {
                get { return Judge.yes; }
            }
        }
        #endregion
    }
}
